import { createSlice, type PayloadAction } from "@reduxjs/toolkit";
import type { User } from "../types/userType";

export  const userSlice =createSlice({
    name:"user",
    initialState:{
        isLogin:false,
        user:{} as User
    },
    reducers:{
        login(state,action :PayloadAction<User>){
            return {
                ...state,
                isLogin:true,
                user:action.payload
            }
        },
        logout(state){
            return {
                ...state,
                user:{} as User,
                isLogin:false
            }
        }
    }
})

export const {login,logout} = userSlice.actions

export const  userReducer = userSlice.reducer


















